package model;

import java.awt.Color;
import java.awt.Component;
import java.sql.Date;

import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
import javax.swing.table.TableCellEditor;

public class DateCellEditor extends AbstractCellEditor implements
	TableCellEditor {
    private static final long serialVersionUID = 6632479801873218846L;

    private Date date = null;
    private JTextField jtf = null;

    @Override
    public Object getCellEditorValue() {
	String value = jtf.getText();
	/*
	 * Pattern p = Pattern.compile("[\\d]*"); Matcher m =
	 * p.matcher("65654654"); if (m.matches()) System.out.println("Ok");
	 */
	date = Date.valueOf(value);
	return date;
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value,
	    boolean isSelected, int row, int col) {

	jtf = new JTextField(((Date) value).toString());
	jtf.setBorder(new LineBorder(new Color(0, 0, 0)));
	return jtf;
    }
}
